home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu332 / 332doc.arc / 332BUGC4 < prev    next >
Text File  |  1989-12-19  |  24KB  |  1,062 lines

  1.                                                                       
  2.   DEBUG MONITOR USER'S MANUAL    MOTOROLA
  3.   5-1     M68332BUG
  4.  
  5.                                                                       
  6.   DEBUG MONITOR USER'S MANUAL    MOTOROLA
  7.   M68332BUG    5-1
  8.  
  9.  
  10. CHAPTER 5
  11.  
  12. SYSTEM CALLS
  13.  
  14.  
  15.  
  16. 5.1  INTRODUCTION
  17.  
  18. This chapter describes the 332Bug TRAP #15 handler, which allows system calls from user 
  19. programs.  System calls access selected functional routines contained within 332Bug, 
  20. including input and output routines.  TRAP #15 also transfers control back to 332Bug at the 
  21. end of a user program (refer to the .RETURN function, paragraph 5.2.14).
  22.  
  23. In the descriptions of some input and output functions, reference is made to the default input 
  24. port or the default output port.  After power-up or reset, the default input and output port is port 
  25. 0 (the M68332BCC terminal port).
  26.  
  27.  
  28. 5.1.1  Executing System Calls Through TRAP #15
  29.  
  30. To execute a system call from a user program simply insert a TRAP #15 instruction into the 
  31. source program.  The code corresponding to the particular system routine is specified in the 
  32. word following the TRAP opcode, as shown in the following example.
  33.  
  34. Format in user program:
  35.  
  36.     TRAP #15    System call to 332Bug
  37.     DC.W  $xxxx    Routine being requested (xxxx = code)
  38.  
  39.  
  40. In some of the examples shown in the following descriptions, a SYSCALL macro is used with 
  41. the Motorola Macro Assembler (MASM) for MS-DOS/PC-DOS machines.  This macro 
  42. automatically assembles the TRAP #15 call followed by the define constant for the function 
  43. code.  The SYSCALL macro is:
  44.  
  45.     SYSCALL    MACRO
  46.         TRAP    #15
  47.         DC.W    \1
  48.         ENDM
  49.  
  50.  
  51. Using the SYSCALL macro, the system call appears in the user program as:
  52.  
  53.     SYSCALL    <routine name>
  54.  
  55.  
  56. It is necessary to create an equate file with the routine names equated to their respective 
  57. codes.
  58.  
  59.  
  60. When using the 332Bug one-line assembler/disassembler, the SYSCALL macro and the 
  61. equates are pre-defined.  Input: SYSCALL, space, function,  carriage return.
  62.  
  63.  
  64. EXAMPLE:
  65.  
  66. 332Bug>M 3000;DI<CR>
  67. 0000 3000 00000000      ORI.B #$0,D0? SYSCALL .OUTLN <CR>
  68. 0000 3000 4E3F0022      SYSCALL .OUTLN
  69. 0000 3004 00000000      ORI.B #$0,D0? . <CR>
  70. 332Bug>
  71.  
  72.  
  73.  
  74. 5.1.2  Input/Output String Formats
  75.  
  76. Within the context of the TRAP #15 handler are two string formats:
  77.  
  78. Pointer/Pointer Format:    The string is defined by a pointer to the first character and a pointer 
  79. to the last character + 1.
  80.  
  81. Pointer/Count Format:    The string is defined by a pointer to a count byte which contains the 
  82. count of the characters in the string followed by the string itself.
  83.  
  84. A line is defined as a string followed by a carriage return and a line feed.
  85.  
  86.  
  87. 5.2  SYSTEM CALL ROUTINES
  88.  
  89. Table 5-1 summarizes the TRAP #15 functions.  Refer to the appropriate paragraph for a 
  90. description of the available system calls.
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. TABLE 5-1.  332Bug System Call Routines
  98.  
  99.     CODE    FUNCTION    DESCRIPTION
  100.  
  101. $0000    .INCHR    Input character
  102. $0001    .INSTAT    Input serial port status
  103. $0002    .INLN    Input line (pointer/pointer format)
  104. $0003    .READSTR    Input string (pointer/count format)
  105. $0004    .READLN    Input line (pointer/count format)
  106. $0005    .CHKBRK    Check for break
  107. $0020    .OUTCHR    Output character
  108. $0021    .OUTSTR    Output string (pointer/pointer format)
  109. $0022    .OUTLN    Output line (pointer/pointer format)
  110. $0023    .WRITE    Output string (pointer/count format)
  111. $0024    .WRITELN    Output line (pointer/count format)
  112. $0025    .WRITDLN    Output line with data (pointer/count format)
  113. $0026    .PCRLF    Output carriage return and line feed
  114. $0027    .ERASLN    Erase line
  115. $0028    .WRITD    Output string with data (pointer/count format)
  116. $0029    .SNDBRK    Send break
  117. $0040    .TM_INI    Timer initialization
  118. $0041    .TM_STR0    Start timer at T=0
  119. $0042    .TM_RD    Read timer 
  120. $0043    .DELAY    Timer delay function
  121. $0063    .RETURN    Return to 332Bug
  122. $0064    .BINDEC    Convert binary to Binary Coded Decimal (BCD)
  123. $0067    .CHANGEV    Parse value
  124. $0068    .STRCMP    Compare two strings (pointer/count format)
  125. $0069    .MULU32    Multiply two 32-bit unsigned integers
  126. $006A    .DIVU32    Divide two 32-bit unsigned integers
  127.  
  128.  
  129. .INCHR    Input Character Routine    .INCHR
  130.  
  131.  
  132. 5.2.1  Input Character Routine
  133.  
  134.  
  135. SYSCALL    .INCHR
  136. TRAP CODE:    $0000
  137.  
  138. Reads a character from the default input port.  The character remains in the stack.
  139.  
  140.  
  141. Entry Conditions:
  142.  
  143.     SP ==>    Space for character <byte>
  144.             Word fill <byte>
  145.  
  146.  
  147. Exit Conditions:
  148.  
  149.     SP ==>    Character <byte>
  150.             Word fill <byte>
  151.  
  152.  
  153. EXAMPLE:
  154.  
  155.     SUBQ.L    #2,SP    Allocate space for result
  156.     SYSCALL    .INCHR    Call .INCHR
  157.     MOVE.B    (SP)+,D0    Load character in D0
  158.  
  159.  
  160.  
  161. .INSTAT    Input Serial Port Status    .INSTAT
  162.  
  163.  
  164. 5.2.2  Input Serial Port Status
  165.  
  166.  
  167. SYSCALL    .INSTAT
  168. TRAP CODE:    $0001
  169.  
  170. Checks the default input port buffer for characters.  The condition codes are set to indicate the 
  171. result of the operation.
  172.  
  173.  
  174. Entry Conditions:
  175.  
  176.     No arguments or stack allocation required
  177.  
  178.  
  179. Exit Conditions:
  180.  
  181.     Z (zero) = 1 if the receiver buffer is empty
  182.  
  183.  
  184. EXAMPLE:
  185.  
  186. LOOP    SYSCALL    .INSTAT    Any characters?
  187.     BEQ.S    EMPTY    No, branch
  188.     SUBQ.L    #2,A7    Yes, then
  189.     SYSCALL    .INCHR    Read them
  190.     MOVE.B    (SP)+,(A0)+    In buffer
  191.     BRA.S    LOOP    Check for more
  192. EMPTY
  193.  
  194. .INLN    Input Line Routine    .INLN
  195.  
  196.  
  197. 5.2.3  Input Line Routine
  198.  
  199.  
  200. SYSCALL    .INLN
  201. TRAP CODE:    $0002
  202.  
  203. Reads a line from the default input port.  The minimum buffer size is 256 bytes.
  204.  
  205.  
  206. Entry Conditions:
  207.  
  208.     SP ==>    Address of string buffer <long>
  209.  
  210.  
  211. Exit Conditions:
  212.  
  213.     SP ==>    Address of last character in the string+1 <long>
  214.  
  215.  
  216. EXAMPLE:
  217.  
  218. If A0 contains the string destination address:
  219.  
  220.     SUBQ.L    #4,A7    Allocate space for result
  221.     PEA    (A0)    Push pointer to destination
  222.     TRAP    #15    (May also invoke by SYSCALL
  223.     DC.W    2    macro (''SYSCALL .INLN'')
  224.     MOVE.L    (A7)+,A1    Retrieve address of last character+1
  225.  
  226.  
  227.  
  228. NOTE
  229.  
  230. A line is a string of characters terminated by a carriage return (<CR>).  The 
  231. maximum allowed size is 254 characters.  The terminating <CR> is not included 
  232. in the string.  See control character processing as described in paragraph 1.7, 
  233. Terminal Input/Output Control.
  234.  
  235. .READSTR    Read String Into Variable-Length Buffer    .READSTR
  236.  
  237.  
  238. 5.2.4  Read String Into Variable-Length Buffer
  239.  
  240.  
  241. SYSCALL    .READSTR
  242. TRAP CODE:    $0003
  243.  
  244. Reads a string of characters from the default input port into a buffer.  The first byte in the buffer 
  245. defines the maximum number of characters that can be written to the buffer.  The buffer's size 
  246. should be no less than the first byte + 2.  The maximum number of characters written to a 
  247. buffer is 254 characters, making  the maximum buffer size 256.  On exit, the count byte 
  248. defines the number of characters in the buffer.  Enter a carriage return (<CR>) and line feed 
  249. (<LF>) to terminate the input.  The characters echo to the default output port.  <CR> is not 
  250. echoed.
  251.  
  252.  
  253. Entry Conditions:
  254.  
  255.     SP ==>    Address of input buffer <long>
  256.  
  257.  
  258. Exit Conditions:
  259.  
  260.     SP ==>    Top of stack
  261.             The count byte containing the number of bytes in the buffer.
  262.  
  263.  
  264. EXAMPLE:
  265.  
  266. If A0 contains the string buffer address;
  267.  
  268.     PEA    (A0)    Push buffer address
  269.     TRAP    #15    (May also invoke by SYSCALL
  270.     DC.W    3    macro (''SYSCALL .READSTR'')
  271.  
  272.  
  273.  
  274. NOTE
  275.  
  276. This routine allows the caller to define the maximum character input length (254 
  277. characters).  If more than 254 characters are entered, then the buffer input is 
  278. truncated.  See control character processing as described in paragraph 1.7 
  279. Terminal Input/Output Control.
  280.  
  281. .READLN    Read Line to Fixed-Length Buffer    .READLN
  282.  
  283.  
  284. 5.2.5  Read Line to Fixed-Length Buffer
  285.  
  286.  
  287. SYSCALL    .READLN
  288. TRAP CODE:    $0004
  289.  
  290. Reads a string of characters from the default input port.  Characters echo to the default output 
  291. port.  A string consists of a count byte followed by the characters read from the input.  The 
  292. count byte indicates the number of characters read from the input as well as the number of 
  293. characters in the input string, excluding carriage return <CR> and line feed <LF>.  A string 
  294. may be as many as 254 characters.
  295.  
  296.  
  297. Entry Conditions:
  298.  
  299.     SP ==>    Address of input buffer <long>
  300.  
  301.  
  302. Exit Conditions:
  303.  
  304.     SP ==>    Top of stack
  305.             The first byte in the buffer indicates the string length.
  306.  
  307.  
  308. EXAMPLE:
  309.  
  310. If A0 points to a 256 byte buffer;
  311.  
  312.     PEA    (A0)    Long buffer address
  313.     SYSCALL    .READLN    And read a line from the default input port
  314.  
  315.  
  316.  
  317. NOTE
  318.  
  319. The caller must allocate 256 bytes for a buffer.  Input are limited to 254 
  320. characters.  <CR> and <LF> are sent to default output following echo of the 
  321. input.  See control character processing as described in paragraph 1.7, 
  322. Terminal Input/Output Control.
  323.  
  324. .CHKBRK    Check for Break    .CHKBRK
  325.  
  326.  
  327. 5.2.6  Check for Break
  328.  
  329.  
  330. SYSCALL    .CHKBRK
  331. TRAP CODE:    $0005
  332.  
  333. Returns zero (0) status in condition code register if break status is detected at the default 
  334. input port.
  335.  
  336.  
  337. Entry Conditions:
  338.  
  339.     No arguments or stack allocation required
  340.  
  341.  
  342. Exit Conditions:
  343.  
  344.     Z flag set in CCR if break detected
  345.  
  346.  
  347. EXAMPLE:
  348.  
  349.     SYSCALL    .CHKBRK
  350.     BEQ    BREAK
  351.  
  352. .OUTCHR    Output Character Routine    .OUTCHR
  353.  
  354.  
  355. 5.2.7  Output Character Routine
  356.  
  357.  
  358. SYSCALL    .OUTCHR
  359. TRAP CODE:    $0020
  360.  
  361. Outputs a character to the default output port.
  362.  
  363.  
  364. Entry Conditions:
  365.  
  366.     SP ==>    Character <byte>
  367.             Word fill <byte> (Placed automatically by the MCU)
  368.  
  369.  
  370. Exit Conditions:
  371.  
  372.     SP ==>    Top of stack
  373.             Character is sent to the default I/O port.
  374.  
  375.  
  376. EXAMPLE:
  377.  
  378.     MOVE.B    D0,-(SP)    Send character in D0
  379.     SYSCALL    .OUTCHR    To default output port
  380.  
  381. .OUTSTR    Output String Using Pointers    .OUTSTR
  382. .OUTLN        .OUTLN
  383.  
  384.  
  385. 5.2.8  Output String Using Pointers
  386.  
  387.  
  388. SYSCALL    .OUTSTR
  389. TRAP CODE:    $0021
  390.  
  391. SYSCALL    .OUTLN
  392. TRAP CODE:    $0022
  393.  
  394.  
  395. .OUTSTR outputs a string of characters to the default output port.  .OUTLN outputs a string of 
  396. characters followed by a <CR><LF> sequence.
  397.  
  398.  
  399. Entry Conditions:
  400.  
  401.     SP ==>    Address of first character <long>
  402.             +4    Address of last character + 1 <long>
  403.  
  404.  
  405. Exit Conditions:
  406.  
  407.     SP ==>    Top of stack
  408.  
  409.  
  410. EXAMPLE:
  411.  
  412. If A0 = start of string and A1 = end of string+1
  413.  
  414.     MOVEM.L    A0/A1,-(SP)    Load pointers to string
  415.     SYSCALL    .OUTSTR    And print it
  416.  
  417. .WRITE    Output String Using Character Count    .WRITE
  418. .WRITELN        .WRITELN
  419.  
  420.  
  421. 5.2.9  Output String Using Character Count
  422.  
  423.  
  424. SYSCALL    .WRITE
  425. TRAP CODE:    $0023
  426.  
  427. SYSCALL    .WRITELN
  428. TRAP CODE:    $0024
  429.  
  430.  
  431. .WRITE and .WRITELN format character strings with a count byte and output the string to the 
  432. default output port.  After formatting, the count byte is the first byte in the string.  The user 
  433. passes the starting address of the string.  .WRITELN appends a <CR><LF> to the end of the 
  434. string.
  435.  
  436.  
  437. Entry Conditions:
  438.  
  439.     Four bytes of parameters are positioned in the stack as follows:
  440.  
  441.     SP ==> Address of first character.<long>
  442.     +4; Address of last character +1 <long>.
  443.  
  444.  
  445. Exit Conditions:
  446.  
  447.     SP ==>    Top of stack
  448.  
  449.  
  450. EXAMPLE:
  451.  
  452.  
  453. MESSAGE1    DC.B    9,    "MOTOROLA "
  454. MESSAGE2    DC.B    8,    "QUALITY!"
  455.  
  456.     PEA    MESSAGE1(PC)    Push address of string
  457.     SYSCALL    .WRITE    Use TRAP #15 macro
  458.     PEA    MESSAGE2(PC)    Push address of other string
  459.     SYSCALL    .WRITE    Invoke function again
  460.  
  461.  
  462. .WRITE    Output String Using Character Count    .WRITE
  463. .WRITELN        .WRITELN
  464.  
  465.  
  466.  . . . . . would print out the following message:
  467.  
  468. MOTOROLA QUALITY!
  469.  
  470.  
  471. Using .WRITELN instead of .WRITE outputs the following message:
  472.  
  473. MOTOROLA
  474. QUALITY!
  475.  
  476. NOTE
  477.  
  478. The string must be formatted such that the first byte (the byte pointed to by the 
  479. passed address) contains the byte count of the string.
  480.  
  481. .PCRLF    Print <CR><LF>    .PCRLF
  482.  
  483.  
  484. 5.2.10  Print <CR><LF>
  485.  
  486.  
  487. SYSCALL    .PCRLF
  488. TRAP CODE:    $0026
  489.  
  490. .PCRLF sends a carriage return (<CR>) and a line feed (<LF>) to the default output port.
  491.  
  492.  
  493. Entry Conditions:
  494.  
  495.     No arguments or stack allocation required.
  496.  
  497.  
  498. Exit Conditions:
  499.  
  500.     None
  501.  
  502.  
  503. EXAMPLE:
  504.  
  505.     SYSCALL    .PCRLF    Output <CR><LF>
  506.  
  507. .ERASLN    Erase Line    .ERASLN
  508.  
  509.  
  510. 5.2.11  Erase Line
  511.  
  512.  
  513. SYSCALL    .ERASLN
  514. TRAP CODE:    $0027
  515.  
  516. Use .ERASLN to erase the line at the present cursor position.  If the terminal type flag is set 
  517. for hardcopy mode, a carriage return (<CR>) and line feed (<LF>) are issued instead.
  518.  
  519.  
  520. Entry Conditions:
  521.  
  522.     No arguments required.
  523.  
  524.  
  525. Exit Conditions:
  526.  
  527.     The cursor is positioned at the beginning of a blank line.
  528.  
  529.  
  530. EXAMPLE:
  531.  
  532.     SYSCALL    .ERASLN
  533.  
  534. .WRITD    Output String with Data    .WRITD
  535. .WRITDLN        .WRITDLN
  536.  
  537.  
  538. 5.2.12  Output String with Data
  539.  
  540.  
  541. SYSCALL    .WRITD
  542. TRAP CODE:    $0028
  543.  
  544. SYSCALL    .WRITDLN
  545. TRAP CODE:    $0025
  546.  
  547. These trap functions use the monitor I/O routine which outputs a user string containing 
  548. embedded variable fields.  The user passes the starting address of the string and the data 
  549. stack address containing the data which is inserted into the string.  The output goes to the 
  550. default output port.
  551.  
  552.  
  553. Entry Conditions:
  554.  
  555. Eight bytes of parameter positioned in the stack as follow:
  556.  
  557.     SP ==>    Address of string <long>
  558.             Data list pointer <long>
  559.  
  560. A separate data stack or data list arranged as follows:
  561.  
  562. Data list pointer =>    Data for 1st variable in string    <long>
  563.     Data for next variable    <long>
  564.     Data for next variable    <long>
  565.  
  566.  
  567. Exit Conditions:
  568.  
  569.     SP ==>    Top of stack
  570.  
  571. .WRITD    Output String with Data    .WRITD
  572. .WRITDLN        .WRITDLN
  573.  
  574.  
  575. EXAMPLE:
  576.  
  577. The following section of code .....
  578.  
  579. ERRMESSG    DC.B    $15,'ERROR CODE = ','|10,8Z|'
  580.     MOVE.L    #3,-(A5)    Push error code on data stack
  581.     PEA    (A5)    Push data stack location
  582.     PEA    ERRMESSG(PC)    Push address of string
  583.     SYSCALL    .WRITDLN    Invoke function
  584.     TST.L    (A5)+    De-allocate data from data stack
  585.  
  586.  . . . . . would print the message:
  587.  
  588. ERROR CODE = 3
  589.  
  590.  
  591.  
  592. NOTE
  593.  
  594. The string must be formatted such that the first byte (the byte pointed to by the 
  595. passed address) contains the byte count of the string, including the data field 
  596. specifiers.
  597.  
  598. Format data fields within the string as follows: '|<radix>,<fieldwidth>[Z]|' where 
  599. <radix> is the data's numerical base (in hexadecimal, i.e., ''A'' is base 10, ''10'' 
  600. is base 16, etc.) and <fieldwidth> is the number of data characters to output.  
  601. The data is right-justified and left-most characters are truncated to size.  Include 
  602. ''Z'' to suppress leading zeros in the output.
  603.  
  604. All data is placed in the stack as longwords.  Each time a data field is 
  605. encountered in the user string, a longword is displayed from the data stack.
  606.  
  607. The data stack is not destroyed by this routine.  Use the call routine (see 
  608. example above) to de-allocate space in the data stack.  If it is necessary for the 
  609. space in the data stack to be deallocated, it must be done using the call routine, 
  610. as shown in the above example.
  611.  
  612. .SNDBRK    Send Break    .SNDBRK
  613.  
  614.  
  615. 5.2.13  Send Break
  616.  
  617.  
  618. SYSCALL    .SNDBRK
  619. TRAP CODE:    $0029
  620.  
  621. Use .SNDBRK to send a break to the default output port.
  622.  
  623.  
  624. Entry Conditions:
  625.  
  626.     No arguments or stack allocation required
  627.  
  628.  
  629. Exit Conditions:
  630.  
  631.     The default port is sent ''break''.
  632.  
  633.  
  634. EXAMPLE:
  635.  
  636.     SYSCALL    .SNDBRK
  637.  
  638. .TM_INI    Timer Initialization    .TM_INI
  639.  
  640.  
  641. 5.2.14  Timer Initialization
  642.  
  643.  
  644. SYSCALL    .TM_INI
  645. TRAP CODE:    $0040
  646.  
  647.  
  648. Use .TM_INI to initialize the MC68332 MCU periodic interrupt timer.  .TM_INI stops the timer 
  649. and then initializes it.  .TM_INI does not restart the timer; use .TM_STR0 to restart the timer.  
  650. Timing is accomplished by counting the number of interrupt pulses generated.  The default 
  651. interrupt pulse frequency is 125 milliseconds.  Use this routine the first time the timer 
  652. functions are used.
  653.  
  654.  
  655. Entry Conditions:
  656.  
  657.     No arguments required.
  658.  
  659.  
  660. Exit Conditions Different From Entry:
  661.  
  662.     Periodic interrupt timer is stopped (no interrupts) and initialized for future 
  663. operation.
  664.  
  665. EXAMPLE:
  666.  
  667.     SYSCALL    .TM_INI    Initialize timer
  668.  
  669.  
  670. .TM_STR0    Start Timer at T=0    .TM_STR0
  671.  
  672.  
  673. 5.2.15  Start Timer at T=0
  674.  
  675.  
  676. SYSCALL    .TM_STR0
  677. TRAP CODE:    $0041
  678.  
  679.  
  680.  
  681. Use this routine to reset the timer to 0 and start it.  The user can select values for the 
  682. MC68332 MCU periodic interrupt timer (periodic interrupt timing register (PICR) and periodic 
  683. interrupt control register (PITR)), or use the default values.  The default values set the 
  684. interrupt frequency to 125 milliseconds and use level 6, vector 66.  See Appendix C and 
  685. MC68332 Overview, paragraph 4.1.7 Periodic Interrupt Timer for more details.
  686.  
  687.  
  688. Entry Conditions:
  689.  
  690.     SP ==>    Timer control value (for PICR) <word>
  691.         Timer period value (for PITR) <word>
  692.  
  693.  
  694. Exit Conditions Different From Entry:
  695.  
  696.     Parameters are removed from the stack, the timer is started, and the 
  697. interrupt pulse counter is cleared.  If the user's interrupt level, as defined 
  698. in the status register (SR), disables the timer interrupts, the SR interrupt 
  699. mask bits are changed to allow timer interrupts.
  700.  
  701.     If the value of PICR is not equal to the power-up default value, $000F, the 
  702. old vector number is restored to the default 332Bug value.
  703.  
  704.  
  705. EXAMPLE 1:
  706.  
  707.     SYSCALL    .TM_STR0
  708.  
  709.  
  710.  
  711. EXAMPLE 2:
  712.  
  713.     MOVE.L    #0,-(A7)    Reset the timer to zero and start it with the default 
  714. values.
  715.     SYSCALL    .TM_STR0
  716.  
  717.  
  718.  
  719.  
  720. .TM_STR0    Start Timer at T=0    .TM_STR0
  721.  
  722.  
  723. EXAMPLE 3:
  724.  
  725.     MOVE.L    #$00000002,-(A7)    Reset the timer to zero and start it with the default 
  726. control value (PICR) and a period value (PITR) of 
  727. $0002 (=244 usec/interrupt).
  728.     SYSCALL    .TM_STR0
  729.  
  730.  
  731.  
  732. EXAMPLE 4:
  733.  
  734.     MOVE.L    #$054400A0,-(A7)    Reset the timer to zero and start it with the control 
  735. value (PICR) of $0544 (level 5, vector 68 = $44) 
  736. and a period value (PITR) of $00A0 (=19.5 
  737. msec/interrupt).
  738.     SYSCALL    .TM_STR0
  739.  
  740.  
  741.  
  742. .TM_RD    Read Timer     .TM_RD
  743.  
  744.  
  745. 5.2.16  Read Timer
  746.  
  747.  
  748. SYSCALL    .TM_RD
  749. TRAP CODE:    $0042
  750.  
  751.  
  752. Use this routine to read the timer value (the timer value is the number of interrupt pulses 
  753. generated).  Initialize (.TM_INI) and start (.TM_STR0) the timer before using the .TM_RD 
  754. function.
  755.  
  756.  
  757. Entry Conditions:
  758.  
  759.     SP ==>    Space for result <long>
  760.  
  761.  
  762. Exit Conditions Different From Entry:.
  763.  
  764.     SP ==>    Time (number of interrupt pulses) <long>.  The timer keeps 
  765. running after the read.
  766.  
  767.  
  768. EXAMPLE:
  769.  
  770.     SUBQ.L    #4,A7    Allocate space for result
  771.     SYSCALL    .TM_RD    Read timer
  772.     MOVE.L    (SP)+,D0    Load interrupt pulse count
  773.  
  774.  
  775.  
  776. .DELAY    Timer Delay Function    .DELAY
  777.  
  778.  
  779. 5.2.17  Timer Delay Function
  780.  
  781.  
  782. SYSCALL    .DELAY
  783. TRAP CODE:    $0043
  784.  
  785.  
  786. The .DELAY function generates timing delays based on the processor clock.  This function 
  787. uses the MC68332 MCU periodic interrupt timer for operation.  The user specifies the desired 
  788. delay count (number of interrupt pulses generated).  .DELAY returns system control to the 
  789. user after the specified delay is completed.  Initialize (.TM_INI) and start (.TM_STR0) the timer 
  790. before using the .TM_RD function.
  791.  
  792.  
  793. Entry Conditions:
  794.  
  795.     SP ==>    Delay time (number of interrupt pulses) <long>
  796.  
  797.  
  798. Exit Conditions Different From Entry:
  799.  
  800.     SP ==>    The timer keeps running after the delay and parameters are 
  801. removed from the stack.
  802.  
  803.  
  804. EXAMPLE:
  805.  
  806.     SYSCALL    .TM INI    Initialize timer
  807.     SYSCALL    .TM_STR0    Start timer
  808.     PEA.L    &1500    Load a 1500 interrupt pulse delay
  809.     SYSCALL    .DELAY
  810.     *
  811.     *
  812.     *
  813.     PEA.L    &50000    Load a 50000 interrupt pulse delay
  814.     SYSCALL    .DELAY
  815.  
  816.  
  817.  
  818.  
  819. .RETURN    Return to 332Bug    .RETURN
  820.  
  821.  
  822. 5.2.18  Return to 332Bug
  823.  
  824.  
  825. SYSCALL    .RETURN
  826. TRAP CODE:    $0063
  827.  
  828. .RETURN restores control to 332Bug from the target program.  First, any breakpoints 
  829. inserted in target code are removed.  Then the target state is saved in the register image 
  830. area.  Finally, the routine returns to 332Bug.
  831.  
  832.  
  833. Entry Conditions:
  834.  
  835.     No arguments required.
  836.  
  837.  
  838. Exit Conditions:
  839.  
  840.     Control is returned to 332Bug.
  841.  
  842.  
  843. EXAMPLE:
  844.  
  845.     SYSCALL    .RETURN    Return to 332Bug
  846.  
  847. .BINDEC    Calculate BCD Equivalent Specified Binary Number    .BINDEC
  848.  
  849.  
  850. 5.2.19  Calculate BCD Equivalent Specified Binary Number
  851.  
  852.  
  853. SYSCALL    .BINDEC
  854. TRAP CODE:    $0064
  855.  
  856. This function takes a 32-bit unsigned binary number and changes it to its equivalent BCD 
  857. (Binary Coded Decimal Number).
  858.  
  859.  
  860. Entry Conditions:
  861.  
  862.     SP ==>    Argument:  Hex number    <long>
  863.         Space for result    <2 long>
  864.  
  865.  
  866. Exit Conditions:
  867.  
  868.     SP ==>    Decimal number    (2 Most Significant Digits)    <long>
  869.             (8 Most Significant Digits)    <long>
  870.  
  871.  
  872. EXAMPLE:
  873.  
  874.     SUBQ.L    #8,A7    Allocate space for result
  875.     MOVE.L    D0,-(SP)    Load hex number
  876.     SYSCALL    .BINDEC    Call .BINDEC
  877.     MOVEM.L    (SP)+,D1/D2    Load result
  878.     SYSCALL    .REDIR    Redirect I/O function
  879.  
  880. .CHANGEV    Parse Value, Assign to Variable    .CHANGEV
  881.  
  882.  
  883. 5.2.20  Parse Value, Assign to Variable
  884.  
  885.  
  886. SYSCALL    .CHANGEV
  887. TRAP CODE:    $0067
  888.  
  889. Parse a value in the user specified buffer.  If the user specified buffer is empty, the user is 
  890. prompted for a new value, otherwise update the integer offset into the buffer to skip the value.  
  891. The new value is displayed and assigned to the variable unless the user's input is an empty 
  892. string.
  893.  
  894.  
  895. Entry Conditions:
  896.  
  897.     SP ==>    Address of 32-bit offset into user's buffer
  898.         Address of user's buffer (pointer/count format string) 
  899.         Address of 32-bit integer variable to change
  900.         Address of string to use in prompting and displaying value
  901.  
  902.  
  903. Exit Conditions:
  904.  
  905.     SP ==>    Top of stack
  906.  
  907.  
  908. EXAMPLE:
  909.  
  910. PROMPT    DC.B    $14,'COUNT = |10,8|'
  911. GETCOUNT    PEA    PROMPT(PC)    Point to prompt string
  912.     PEA    COUNT    Point to variable to change
  913.     PEA    BUFFER    Point to buffer
  914.     PEA    POINT    Point to offset into buffer
  915.     SYSCALL    .CHANGEV    Make the system call
  916.     RTS        COUNT changed, return
  917.  
  918. .CHANGEV    Parse Value, Assign to Variable    .CHANGEV
  919.  
  920.  
  921. If the above code was called with a syscall routine and BUFFER contained ''1 3'' in 
  922. pointer/count format and POINT contained 2 (longwords), then COUNT would be assigned 
  923. the value 3, and POINT would contain 4 (pointing to first character past 3).  Note that POINT is 
  924. the offset of the buffer start address (not the address of the first character in the buffer) to the 
  925. next character to process.  In this case, a value of 2 in POINT indicates that the space 
  926. between 1 and 3 is the next character to be processed.  After calling .CHANGEV, the screen 
  927. would display the following line:
  928.  
  929.     COUNT = 3
  930.  
  931. If the above code was called again, nothing could be parsed from BUFFER, so a prompt 
  932. would be issued.  For example, if the string 5 is entered in response to the prompt.
  933.  
  934.     COUNT = 3? 5<CR>
  935.     COUNT = 5
  936.  
  937. If in the previous example nothing had been entered at the prompt, COUNT would retain its 
  938. prior value.
  939.  
  940.     COUNT = 3? <CR>
  941.     COUNT = 3
  942.  
  943. .STRCMP    Compare Two Strings    .STRCMP
  944.  
  945.  
  946. 5.2.21  Compare Two Strings
  947.  
  948.  
  949. SYSCALL    .STRCMP
  950. TRAP CODE:    $0068
  951.  
  952. An equality comparison is made and a boolean flag is returned to the caller.  If the strings are 
  953. not identical the flag is $00, otherwise it is $FF.
  954.  
  955.  
  956. Entry Conditions:
  957.  
  958.     SP ==>    Address of string#1
  959.         Address of string#2
  960.         Three bytes (unused)
  961.         Byte to receive string comparison result
  962.  
  963.  
  964. Exit Conditions:
  965.  
  966.     SP ==>    Three bytes (unused)
  967.         Byte that received string comparison result
  968.  
  969.  
  970. EXAMPLE:
  971.  
  972. If A1 and A2 contain the addresses of the two strings.
  973.  
  974.     SUBQ.L    #4,SP     Allocate longword to receive result
  975.     PEA    (A1)    Push address of one string
  976.     PEA    (A2)    Push address of the other string
  977.     SYSCALL    .STRCMP    Compare the strings
  978.     MOVE.L    (SP)+,D0    Pop boolean flag into data register
  979.     TST.B    D0    Check boolean flag
  980.     BNE    ARE SAME    Branch if strings are identical
  981.  
  982. .MULU32    Unsigned 32 x 32 Bit Multiply    .MULU32
  983.  
  984.  
  985. 5.2.22  Unsigned 32 x 32 Bit Multiply
  986.  
  987.  
  988. SYSCALL    .MULU32
  989. TRAP CODE:    $0069
  990.  
  991. Multiply two 32-bit unsigned integers and return the product on the stack as a 32-bit unsigned 
  992. integer.  No overflow checking is performed.
  993.  
  994.  
  995. Entry Conditions:
  996.  
  997.     SP ==>    32-bit multiplier
  998.         32-bit multiplicand
  999.         32-bit space for result
  1000.  
  1001.  
  1002. Exit Conditions:
  1003.  
  1004.     SP ==>    32-bit product (result from multiplication)
  1005.  
  1006.  
  1007. EXAMPLE:
  1008.  
  1009. Multiply D0 by D1, load result into D2.
  1010.  
  1011.     SUBQ.L    #4,SP    Allocate space for result
  1012.     MOVE.L    D0,-(SP)    Push multiplicand
  1013.     MOVE.L    D1,-(SP)     Push multiplier
  1014.     SYSCALL    .MULU32    Multiply D0 by D1
  1015.     MOVE.L    (SP)+,D2    Get product
  1016.  
  1017. .DIVU32    Unsigned 32 x 32 Bit Divide    .DIVU32
  1018.  
  1019.  
  1020. 5.2.23  Unsigned 32 x 32 Bit Divide
  1021.  
  1022.  
  1023. SYSCALL    .DIVU32
  1024. TRAP CODE:    $006A
  1025.  
  1026. Divide two 32-bit unsigned integers and return the quotient on the stack as a 32-bit unsigned 
  1027. integer.  The case of division by zero is handled by returning the maximum unsigned value 
  1028. $FFFFFFFF.
  1029.  
  1030.  
  1031. Entry Conditions:
  1032.  
  1033.     SP ==>    32-bit divisor (value to divide by)
  1034.         32-bit dividend (value to divide)
  1035.         32-bit space for result
  1036.  
  1037.  
  1038. Exit Conditions:
  1039.  
  1040.     SP ==>    32-bit quotient (result from division)
  1041.  
  1042.  
  1043. EXAMPLE:
  1044.  
  1045. Divide D0 by D1, load result into D2.
  1046.  
  1047.     SUBQ.L    #4,SP    Allocate space for result
  1048.     MOVE.L    D0,-(SP)    Push dividend
  1049.     MOVE.L    D1,-(SP)    Push divisor
  1050.     SYSCALL    .DIVU32    Divide D0 by D1
  1051.     MOVE.L    (SP)+,D2    Get quotient
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.